package com.wish.finance.controller;

import java.math.BigDecimal;
import java.util.*;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jeequan.jeepay.Jeepay;
import com.jeequan.jeepay.JeepayClient;
import com.jeequan.jeepay.exception.JeepayException;
import com.jeequan.jeepay.model.PayOrderCreateReqModel;
import com.jeequan.jeepay.request.PayOrderCreateRequest;
import com.jeequan.jeepay.response.PayOrderCreateResponse;
import com.wish.base.dto.*;
import com.wish.base.entity.*;
import com.wish.base.service.ICfContractService;
import com.wish.base.service.ICwDealPerDayService;
import com.wish.base.service.ICwPaymentPlanService;
import com.wish.base.service.ICwReceiptPlanService;
import com.wish.common.core.web.domain.AjaxResult;
import com.wish.common.security.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wish.common.security.annotation.PreAuthorize;
import com.wish.common.core.web.controller.BaseController;
import com.wish.common.core.web.page.TableDataInfo;

/**
 * 收款计划Controller
 * 
 * @author wish
 * @date 2022-05-26
 */
@RestController
@RequestMapping("/plan")
public class TCwReceiptPlanController extends BaseController
{
    @Autowired
    ICwReceiptPlanService cwReceiptPlanService;

    /**
     * 查询支付订单（支付流水信息）列表
     */
    @PreAuthorize(hasPermi = "system:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(CwReceiptPlanDto dto)
    {
        startPage();
        QueryWrapper<CwReceiptPlan> wrapper = new QueryWrapper<>();
        if (StringUtils.isNoneBlank(dto.getContractNo())) {
            wrapper.like("contract_no",dto.getContractNo());
        }
        if (dto.getCollectionDateStart() != null) {
            wrapper.ge("collection_date",dto.getCollectionDateStart());
        }
        if (dto.getCollectionDateEnd() != null) {
            wrapper.le("collection_date",dto.getCollectionDateEnd());
        }
        if (dto.getSkStatus() != null) {
            wrapper.eq("sk_status",dto.getSkStatus());
        }
        if (dto.getRealCollectionDateStart() != null) {
            wrapper.ge("real_collection_date",dto.getRealCollectionDateStart());
        }
        if (dto.getRealCollectionDateEnd() != null) {
            wrapper.le("real_collection_date",dto.getRealCollectionDateEnd());
        }
        if (dto.getBillType() != null) {
            wrapper.eq("bill_type",dto.getBillType());
        }
        wrapper.eq("receipt_type",dto.getReceiptType());
        startPage();
        List<CwReceiptPlan> list = cwReceiptPlanService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 收款计划数据查询
     */
    @PreAuthorize(hasPermi = "finance:plan:sumList")
    @GetMapping("/sumList")
    //收款计划模糊查询及列表展示
    public TableDataInfo sumList(CwReceiptPlanDto cwReceiptPlanDto)
    {
        startPage();
        List<CwReceiptPlan> list = cwReceiptPlanService.sumList(cwReceiptPlanDto);
        return getDataTable(list);
    }

    @Autowired
    ICwPaymentPlanService itCwPaymentPlanService;



    /*获取所有账单类型*/
    @GetMapping("itemTypeList")
    public ItemType[] itemTypeList() {
        ItemType[] values = ItemType.values();
        return values;
    }

    /*获取所有付款状态*/
    @GetMapping("payStateList")
    public PayState[] payStateList() {
        PayState[] values = PayState.values();
        return values;
    }

    /*获取所有付款类型*/
    @GetMapping("billTypeList")
    public BillType[] payTypeList() {
        BillType[] values = BillType.values();
        return values;
    }

    /*获取所有支付方式*/
    @GetMapping("payMethodList")
    public PayMethod[] payMethodList() {
        PayMethod[] values = PayMethod.values();
        return values;
    }


    @Autowired
    ICfContractService itCfContractService;

    @GetMapping("/getMsg")
    public AjaxResult getMsg(CfContract contract) {
        CfContract byId = itCfContractService.getById(contract.getId());
        return AjaxResult.success(byId);
    }
}
